<template>
	<view class="box">
	
		
		<u-popup v-model="dinggou" mode="center" width="90%" :mask-close-able='false'>
			<view class="d_f j_c_c">
				<image src="https://web.78keji.cn/keepimg/popo.png" mode="widthFix" style="width: 580rpx;"></image>
			</view>
			<view class="d_f j_c_c" style="margin-top: 41rpx;">
				<image src="https://web.78keji.cn/keepimg/bt.png" mode="widthFix" style="width: 528rpx;"
					@click="dinggou=false"></image>
			</view>
		
		</u-popup>
		<u-popup v-model="showx" mode="center" width="90%" :mask-close-able='false'>
		
					<image src="https://web.78keji.cn/keepimg/xcx/zfb.png" mode="widthFix" style="width: 100%;position: relative;"></image>
		
					<view class="" style="width: 100%;position: absolute;top: 30rpx;">
						<view class="d_f j_c_c" style="color: #2A63D9;font-size: 36rpx;">
							确认到账支付宝账号
						</view>
						<view class="d_f j_c_c" style="width: 100%;margin-top: 48rpx;">
							<view class="d_f a_i_c "
								style="border: 1px solid #B3B3B3;width: 560rpx;height: 80rpx;border-radius: 40rpx;padding: 0 23rpx;">
								<image src="https://web.78keji.cn/keepimg/xcx/icon.png" mode="widthFix" style="width: 43rpx;"></image>
								<view class="" style="width: 1rpx;
		height: 40rpx;border-right: 1px solid #999999;margin-left: 12rpx;">
		
								</view>
								<input  placeholder="请输入领取支付宝账号" style="margin-left: 12rpx;" v-model="content">
							</view>
							<!-- 	<u-input v-model="content" type="text" placeholder-style="color:#B3B3B3" :border="border"
								style="width: 536rpx;margin: 0 auto;" /> -->
						</view>
						<view class="d_f j_c_c">
							<image src="https://web.78keji.cn/keepimg/xcx/zgbbt.png" mode="widthFix" style="width:536rpx;margin-top: 30rpx;"
								@click="viplingqu"></image>
						</view>
		
					</view>
					<view class="d_f j_c_c">
						<image src="https://web.78keji.cn/keepimg/xcx/quxiao.png" mode="widthFix" style="width: 68rpx;" @click="showx=false"></image>
					</view>
		
		
				</u-popup>
	
	<view class="" style="width: 100%;text-align: center;" v-for="(item,index) in data" :key="index">
		
		<view class=""  style="position: relative;"  v-if="item.status==0||item.status==2||item.status==5">
			<image src="https://web.78keji.cn/keepimg/xcx/cdno.png" mode="widthFix" style="width: 100%;"></image>
<!-- 			<image src="https://web.78keji.cn/keepimg/xcx/bts.png" mode="widthFix" style="width: 640rpx;position: absolute;z-index: 9999;left: 55rpx;bottom: 70rpx" @click="alipay(item)"></image> -->
<view class="text-button" @click="alipay(item)" v-if="item.check==false">充电券领取</view>
			      <get-coupon
				  v-else
			          onBeforeGetCoupon="onBeforeGetCoupon"
			          onGetCouponSuccess="onGetCouponSuccess"
			          onGetCouponFail="onGetCouponFail"
			          onUseImmediately="onUseImmediately"
			          onClose="onClose" 
			          :params="zfbPrams"
			          :zIndex="9998"
			          :extraData="'Any Data'"
			      >
			          <view class="text-button">确定领取</view>
			      </get-coupon>
				  
		</view>
		<view class="" v-else style="position: relative;">
			<view class="" >
				<image src="https://web.78keji.cn/keepimg/xcx/cdyes.png" mode="widthFix" style="width: 100%;"></image>
				<image src="https://web.78keji.cn/keepimg/xcx/cdbt.png" mode="widthFix" style="width: 640rpx;position: absolute;z-index: 9;left: 55rpx;bottom: 70rpx" ></image>
			</view>
		
		</view>
		
	</view>
<view class="" style="width: 100%;text-align: center;position: relative" v-for="(items,indexs) in arrs" >
		<image src="https://web.78keji.cn/keepimg/xcx/keeps.png" mode="widthFix" style="width: 750rpx;"   v-if="items.type==1"></image>
		<image src="https://web.78keji.cn/keepimg/xcx/bts.png" mode="widthFix" style="width: 640rpx;position: absolute;z-index: 9;left: 55rpx;bottom: 100rpx" @click="lq(items)" v-if="items.status==0"></image>
		<image src="https://web.78keji.cn/keepimg/xcx/keepyes.png" mode="widthFix" style="width: 640rpx;position: absolute;z-index: 9;left: 55rpx;bottom: 100rpx" v-else></image>
	</view>
	</view>
</template>

<script>
	import {
	ljjList,
	keepList,
	keepLq,
	ljjLq,
	ljjStatusEdit
		
	} from '../../api/index.js'
	import md5 from '@/utils/md5.js'
	export default {
		data() {
			return {
				zfbPrams:[
				
				],
				dinggou:false,
				data:[],
				arrs:[],
				showx:false,
				content:'',//领取帐号
				idx:"",
				mobile:""
			}
		},
		components: {

		},
		methods: {
			onGetCouponSuccess(resultList) {
			
			  console.log('触发了 onGetCouponSuccess 事件')
			  console.log('成功返回结果: ', resultList)
			  if(resultList[0].code=='SUCCESS'){
				ljjStatusEdit({
					openid:uni.getStorageSync('openid'),
					type: 3,
					id:this.idx
				}).then((res)=>{
					this.getljj()
				})
			  }else if(resultList[0].code=='ACTIVITY_NOT_START'){
				  uni.showToast({
				  	title:'活动未开始',
				  	icon: 'none', //将值设置为 success 或者 ''
				  	duration: 2000 //持续时间为 2秒
				  })
			  }else if(resultList[0].code=='COUNT_OVER_LIMIT'){
				  uni.showToast({
				  	title:'领取次数超过限制',
				  	icon: 'none', //将值设置为 success 或者 ''
				  	duration: 2000 //持续时间为 2秒
				  })
			  }else if(resultList[0].code=='BUDGET_NOT_ENOUGH'){
				  uni.showToast({
				  	title:'预算不足',
				  	icon: 'none', //将值设置为 success 或者 ''
				  	duration: 2000 //持续时间为 2秒
				  })
			  }else if(resultList[0].code=='OTHER'){
				  uni.showToast({
				  	title:'其他原因，请联系客服',
				  	icon: 'none', //将值设置为 success 或者 ''
				  	duration: 2000 //持续时间为 2秒
				  })
			  }
			
			},
			onGetCouponFail(result) {
			  console.log('触发了 onGetCouponFail 事件')
			  console.log('失败返回结果: ', result)
			  uni.showToast({
			  	title: result.errorMsg,
			  	icon: 'none', //将值设置为 success 或者 ''
			  	duration: 2000 //持续时间为 2秒
			  })
			},
			// onUseImmediately(event) {
			//   console.log('触发了 onUseImmediately 事件')
			
			//   // 可以跳转到自定义的页面
			 
			// },
			onClose(event) {
			  console.log('触发了 onClose 事件')
			},
			alipay(item){
		for(var i in this.data){
			if(item.id==this.data[i].id){
				this.data[i].check=true
				this.idx=this.data[i].id
			}else{
				this.data[i].check=false
			}
		}
		this.zfbPrams=[
			{
			 activityId: '2024040200826004152128250150',
			 
			 outBizNo:this.idx,
			 
			 voucherCode:this.idx,//非导码模式商家券
			}
		]
			},
			viplingqu() {
				uni.showLoading({
					title: '领取中，请稍等',
					mask: true
				});
				ljjLq({
					openid:this.openid,
					type: 3,
					id: this.idx,
					account: this.content,
					accountType: 1,
					bankType: 2
			
				}).then((res) => {
					uni.showToast({
						title: res.msg,
						icon: "none"
					}); //弹出提示框
					this.showx = false
						this.getljj()
				})
			},
		lq(item){
			console.log(item)
			keepLq({
				openid:this.openid,
				type: 3,
				id: item.id
			}).then((res) => {
				this.dinggou = true
				this.getkeep()
			})
		},
		getljj(){
			ljjList({
				openid:this.openid,
				type: 3,
				proType: 6
			}).then((res)=>{
				console.log(res)
				this.data=res.data
				this.data.forEach((item,index)=>{
					Object.assign(item,{check:false})
				})
					
			})
		},
		getkeep(){
			keepList({
				openid:this.openid,
				type: 3,
				protype: -1
			}).then((res)=>{
				console.log(res)
				this.arrs=res.data
			})
		}
		},
		onLoad(option) {
		
		
			this.$scope.onClose = this.onClose.bind(this)
			    this.$scope.onGetCouponSuccess = this.onGetCouponSuccess.bind(this)
			    this.$scope.onGetCouponFail = this.onGetCouponFail.bind(this)
				// my.alert({
				// 	cintent:uni.getStorageSync('mobile')
				// })
			if(uni.getStorageSync('mobile')){
				
			this.openid=md5.hex_md5(uni.getStorageSync('mobile') + '456')
				uni.setStorageSync('openid',this.openid)
			}
		this.getljj()
		this.getkeep()

		},
		watch: {

		},
		computed: {

		}
	}
</script>

<style lang='scss'>
.box{
	position: relative;
	height: 100%;
	background-color: #F0F6FF ;
}
.text-button{
	width: 640rpx;
	height: 80rpx;
	line-height: 80rpx;
	text-align: center;
	color: white;
	background: linear-gradient(-90deg, #1E7AFF, #65A1FF);
	border-radius: 40rpx;
	position: absolute;z-index: 2;left: 55rpx;bottom: 70rpx
}
</style>